package com.android.vtca.sudoky;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class GameSettings {

	 private static GameSettings m_sInstance = null;
	private Context mContext = null;

	public static final int DIFICULTY_EASY = 0;
	public static final int DIFICULTY_MEDIUM = DIFICULTY_EASY + 1;
	public static final int DIFICULTY_HARD = DIFICULTY_MEDIUM + 1;

	private Boolean bSound = true;
	private int iDifficulty = DIFICULTY_EASY;

	private final String easyPuzzle = "360000000" + "004230800" + "000004200"
			+ "070462003" + "82000000014" + "500013020" + "001900000"
			+ "007148300" + "000000045";

	private final String mediumPuzzle = "6500000070" + "000406000"
			+ "014000005" + "007009000" + "002314700" + "000700800"
			+ "500000630" + "000201000" + "030000097";

	private final String hardPuzzle = "009000000" + "090+06020" + "501078000"
			+ "000000700" + "706040102" + "004000000" + "000720903"
			+ "090301080" + "000000600";

	public GameSettings(Context context) {
		mContext = context;
		m_sInstance = this;
		LoadSettings();
	}

	public void LoadSettings() {
		SharedPreferences _SharedPreferences = PreferenceManager
				.getDefaultSharedPreferences(mContext);
		iDifficulty = _SharedPreferences.getInt(
				mContext.getString(R.string.difficulty), DIFICULTY_EASY);
		bSound = _SharedPreferences.getBoolean(
				mContext.getString(R.string.sound), true);
	}

	public void SaveSettings() {
		SharedPreferences _SharedPreferences = PreferenceManager
				.getDefaultSharedPreferences(mContext);
		_SharedPreferences.edit()
				.putInt(mContext.getString(R.string.difficulty), iDifficulty)
				.commit();
		_SharedPreferences.edit()
				.putBoolean(mContext.getString(R.string.sound), bSound)
				.commit();
	}

	public String getSoundSettingString() {
		if (bSound)
			return mContext.getString(R.string.sound) + ":ON";
		return mContext.getString(R.string.sound) + ":OFF";
	}

	public void setSoundSettingNext() {
		bSound = !bSound;
	}

	public void setDifficultySettingNext() {
		iDifficulty++;
		if (iDifficulty > DIFICULTY_HARD)
			iDifficulty = DIFICULTY_EASY;
	}

	public String getDifficultySettingString() {
		String str_Diff;
		switch (iDifficulty) {
		case DIFICULTY_EASY:
			str_Diff = ":MEDIUM";
			break;
		case DIFICULTY_MEDIUM:
			str_Diff = ":HARD";
			break;

		default:
			str_Diff = ":EASY";
			break;

		}
		return mContext.getString(R.string.difficulty) + str_Diff;
	}

	public static GameSettings GetInstance() {
		return m_sInstance;
	}

	public String getPuzzle(int iDiff) {
		if (iDiff == DIFICULTY_MEDIUM) {
			return mediumPuzzle;
		}
		if (iDiff == DIFICULTY_HARD) {
			return hardPuzzle;
		}
		return easyPuzzle;
	}

	public int getDifficultSetting() {
		return iDifficulty;
	}

	public boolean getSoundSetting() {
		return bSound;
	}

}
